//
//  NotifyViewModel.swift
//  imprint
//
//  Created by 小柠檬🍋 on 2025/1/21.
//

import Foundation
import LeanCloud

class DemoViewModel : BaseViewModel{
    @Published var items = [MsgBean]()
    
    func getData(_ isRefresh: Bool = false) {
        request {
            let jsonObject = """
            {
                "audience": {
                    "alias": ["66128151663c4957cb835e0c"]
                },
                "inapp_message": {
                    "inapp_message": true
                },
                "notification": {
                    "alert": "邀请你语音通话",
                    "android": {
                        "alert": "邀请你语音通话",
                        "alert_type": 7,
                        "badge_add_num": 1,
                        "badge_class": "com.module.launcher.view.MainActivity",
                        "builder_id": 0,
                        "category": "",
                        "intent": {
                        },
                        "large_icon": "",
                        "priority": 0,
                        "sound": "",
                        "style": 0,
                        "title": "我的名字"
                    },
                    "ios": {
                        "alert": "邀请你语音通话",
                        "badge": "+1",
                        "sound": "default"
                    }
                },
                "options": {
                    "apns_production": true,
                    "classification": 1,
                    "third_party_channel": {
                        "honor": {
                            "distribution": "secondary_push",
                            "importance": "NORMAL",
                            "skip_quota": true
                        },
                        "huawei": {
                            "category": "IM",
                            "channel_id": "",
                            "distribution": "secondary_push",
                            "importance": "NORMAL",
                            "receipt_id": "",
                            "skip_quota": true,
                            "target_user_type": 0
                        },
                        "oppo": {
                            "category": "IM",
                            "channel_id": "push_oplus_category_service",
                            "distribution": "secondary_push",
                            "notify_level": 2,
                            "skip_quota": true
                        },
                        "vivo": {
                            "callback_id": "",
                            "category": "IM",
                            "distribution": "secondary_push",
                            "push_mode": 0,
                            "skip_quota": true
                        },
                        "xiaomi": {
                            "channel_id": "130360",
                            "distribution": "secondary_push",
                            "skip_quota": true
                        }
                    },
                    "time_to_live": 86400
                },
                "platform": "all"
            }
            """
            let bean = try await JPushManager.shared.pushJg(jsonObject: jsonObject, modeType: JPushResult.self)
            return bean
        } suc: { bean in
            showLog("请求成功")
            showLog(bean.msg_id ?? "")
        } fail: {
            showLog("请求失败")
            showLog($0.message)
        }
    }
}
